package com.gitee.wsl.coroutines.job.trigger

import com.gitee.wsl.coroutines.job.IJobExecutionContext
import com.gitee.wsl.coroutines.job.trigger.ITrigger.ECompletedExecutionInstruction


interface ITriggerListener {
    /**
     * Get the name of the `TriggerListener`.
     */
    val name: String

    /**
     *
     *
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has fired, and it's associated
     * `[com.helger.quartz.IJobDetail]` is about to be executed.
     *
     *
     *
     * It is called before the `vetoJobExecution(..)` method of this
     * interface.
     *
     *
     * @param trigger
     * The `Trigger` that has fired.
     * @param context
     * The `JobExecutionContext` that will be passed to the
     * `Job`'s`execute(xx)` method.
     */
    fun triggerFired(trigger: ITrigger, context: IJobExecutionContext) {}

    /**
     *
     *
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has fired, and it's associated
     * `[com.helger.quartz.IJobDetail]` is about to be executed.
     * If the implementation vetos the execution (via returning
     * `true`), the job's execute method will not be called.
     *
     *
     *
     * It is called after the `triggerFired(..)` method of this
     * interface.
     *
     *
     * @param trigger
     * The `Trigger` that has fired.
     * @param context
     * The `JobExecutionContext` that will be passed to the
     * `Job`'s`execute(xx)` method.
     */
    fun vetoJobExecution(trigger: ITrigger, context: IJobExecutionContext): Boolean {
        return false
    }

    /**
     *
     *
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has misfired.
     *
     *
     *
     * Consideration should be given to how much time is spent in this method, as
     * it will affect all triggers that are misfiring. If you have lots of
     * triggers misfiring at once, it could be an issue it this method does a lot.
     *
     *
     * @param trigger
     * The `Trigger` that has misfired.
     */
    fun triggerMisfired(trigger: ITrigger?) {}

    /**
     *
     *
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has fired, it's associated
     * `[com.helger.quartz.IJobDetail]` has been executed, and
     * it's `triggered(xx)` method has been called.
     *
     *
     * @param trigger
     * The `Trigger` that was fired.
     * @param context
     * The `JobExecutionContext` that was passed to the
     * `Job`'s`execute(xx)` method.
     * @param triggerInstructionCode
     * the result of the call on the
     * `Trigger`'s`triggered(xx)` method.
     */
    fun triggerComplete(
        trigger: ITrigger,
        context: IJobExecutionContext,
        triggerInstructionCode: ECompletedExecutionInstruction?,
    ) {}
}
